#include "Junction.h"

const float Junction::MotorSpeedDelta = 1000.0f;
const float Junction::MotorTorqueDelta = 100.0f;

Junction::Junction( b2World* world, const b2RevoluteJointDef* jointDef ) :
	m_world( world )
{
	m_joint = dynamic_cast<b2RevoluteJoint*>( m_world->CreateJoint( jointDef ) );
}

Junction::~Junction() {
	m_world->DestroyJoint( m_joint );
}

void Junction::PerformAction( const Action& action ) {
	switch( action ) {
		case Action::StartLeftRotation:
			m_joint->SetMotorSpeed( m_joint->GetMotorSpeed() + MotorSpeedDelta );
			//m_joint->SetMotorTorque( m_joint->GetMotorTorque() + MotorTorqueDelta );
			return;
		case Action::StopLeftRotation:
			m_joint->SetMotorSpeed( m_joint->GetMotorSpeed() - MotorSpeedDelta );
			//m_joint->SetMotorTorque( m_joint->GetMotorTorque() - MotorTorqueDelta );
			return;
		case Action::StartRightRotation:
			m_joint->SetMotorSpeed( m_joint->GetMotorSpeed() - MotorSpeedDelta );
			//m_joint->SetMotorTorque(  m_joint->GetMotorTorque() + MotorTorqueDelta );
			return;
		case Action::StopRightRotation:
			m_joint->SetMotorSpeed( m_joint->GetMotorSpeed() + MotorSpeedDelta );
			//m_joint->SetMotorTorque( m_joint->GetMotorTorque() - MotorTorqueDelta );
			return;
		default:
			return;
	}
}

void Junction::Update( float ) {

}

void Junction::Draw() const {}
